package com.ptu.spzx.controller;


import com.github.pagehelper.PageInfo;
import com.ptu.spzx.domain.Stu.StuAnswer;
import com.ptu.spzx.domain.Stu.Vo.StuAnswerVo;
import com.ptu.spzx.domain.Stu.Vo.StuScoreVo;
import com.ptu.spzx.domain.Stu.dto.StuAnswerDto;
import com.ptu.spzx.domain.Stu.dto.StuAnswerScoreDto;
import com.ptu.spzx.model.vo.common.Result;
import com.ptu.spzx.model.vo.common.ResultCodeEnum;
import com.ptu.spzx.service.IStuAnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author YT
 * @since 2024-01-28
 */
@RestController
@RequestMapping("/sc/exam/stuAnswer")
public class StuAnswerController {
    @Autowired
    private IStuAnswerService stuAnswerService;
    //判卷模块
    @PostMapping(value = "/submitStuAnswer")
    @PreAuthorize("@permissionService.hasPermission('exam:stuAnswer:submitStuAnswer')")
    public Result submitStuAnswer(@RequestBody StuAnswerDto stuAnswerDto){
         stuAnswerService.submitStuAnswer(stuAnswerDto);
         return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //教师提交学生分数
    @PostMapping(value = "/submitStuScore")
    @PreAuthorize("@permissionService.hasPermission('exam:stuAnswer:submitStuScore')")
    public Result submitStuScore(@RequestBody StuAnswerScoreDto stuAnswerScoreDto){
        stuAnswerService.submitStuScore(stuAnswerScoreDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //获取学生成绩列表
    @GetMapping("/getStuScoreList/{examId}/{pageNum}/{pageSize}")
    @PreAuthorize("@permissionService.hasPermission('exam:stuAnswer:getStuScoreList')")
    public Result getStuScoreList(@PathVariable("examId") Long examId,
                                  @PathVariable("pageNum") Integer pageNum,
                                  @PathVariable("pageSize") Integer pageSize){
        PageInfo<StuAnswer> stuAnswerVoList=stuAnswerService.getStuScoreList(examId,pageNum,pageSize);
        return Result.build(stuAnswerVoList,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/getStuAnswer")
    @PreAuthorize("@permissionService.hasPermission('exam:stuAnswer:getStuAnswer')")
    public Result getStuAnswer(@RequestParam String stuId,@RequestParam Long epId){
        StuAnswer stuAnswer=stuAnswerService.getStuAnswer(stuId,epId);
        return Result.build(stuAnswer,ResultCodeEnum.SUCCESS);
    }
}

